package com.cskaoyan.market.controller.wx;

import com.cskaoyan.market.db.domain.MarketSearchHistory;
import com.cskaoyan.market.service.WxSearchService;
import com.cskaoyan.market.util.ResponseUtil;
import com.cskaoyan.market.vo.WxSearchVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("wx/search")
public class WxSearchController {
    @Autowired
    WxSearchService wxSearchService;
    //查询关键字和搜索关键字
    @GetMapping("index")
    public Object index() {
        WxSearchVo wxSearchVo = new WxSearchVo();
        wxSearchVo=wxSearchService.index();
        Object ok= ResponseUtil.ok(wxSearchVo);
        return ok;
    }
    //搜索关键字
    @GetMapping("helper")
    public Object helper(String keyword) {
       List<String> marketKeyword=wxSearchService.helper(keyword);
        Object ok= ResponseUtil.ok(marketKeyword);
        return ok;
    }
    //清除用户搜索关键字
    @PostMapping("clearhistory")
    public Object clearhistory() {
        MarketSearchHistory marketSearchHistory=new MarketSearchHistory();
        marketSearchHistory.setDeleted(false);
        Integer i=wxSearchService.clearHistory(marketSearchHistory);
        if(i>0){
            return ResponseUtil.ok();
        }
        return ResponseUtil.fail();
    }
}
